#pragma once
#include <map>
#include <vector>
#include <cstdint>

namespace linkfabric {

struct TLVFragment {
    uint8_t tag;
    uint8_t flags;       // bit0: is_last
    uint16_t seq;
    uint32_t checksum;
    std::vector<uint8_t> value;
};

class StreamBuffer {
public:
    void addFragment(const TLVFragment& frag);
    bool isComplete() const;
    std::vector<uint8_t> reassemble() const;
    std::vector<uint16_t> missingSeqs() const;

private:
    std::map<uint16_t, TLVFragment> fragments_;
    bool lastReceived_ = false;
};

}